package com.wy.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/set/sc.do")
public class setCookie extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Cookie cookie1 = new Cookie("c-1","-1");
        cookie1.setMaxAge(-1);
        resp.addCookie(cookie1);
        Cookie cookie2 = new Cookie("c0","0");
        cookie2.setMaxAge(0);
        resp.addCookie(cookie2);
        Cookie cookie3 = new Cookie("c50","50");
        cookie3.setMaxAge(50);
        resp.addCookie(cookie3);
        Cookie cookie4 = new Cookie("cPath","cPath");
        cookie4.setPath(req.getContextPath() + "/get");
        resp.addCookie(cookie3);
        System.out.println();
    }
}
